﻿using System;
using System.ComponentModel;
using System.Reflection;

namespace Pixeldyne.Core.Extensions
{
	/// <summary>
	/// Utility extension methods.
	/// </summary>
	public static class Enumerations
	{
		/// <summary>
		/// Gets the enum values description.
		/// </summary>
		/// <param name="value">The enum value.</param>
		public static string GetDescription(this Enum value)
		{
			FieldInfo fi = value.GetType().GetField(value.ToString());

			var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

			return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
		}
	}
}